# _*_ coding : utf-8 _*_
# @Time : 2023/8/24 19:44
# @Author : 寻梦
# @File : 05_get请求的quote方法
# @Project : code
import urllib.request
import urllib.parse

# %E5%91%A8%E6%9D%B0%E4%BC%A6(unicode编码) 周杰伦
# url='https://www.baidu.com/s?ie=UTF-8&wd=%E5%91%A8%E6%9D%B0%E4%BC%A6&tn=15007414_dg'

# 需求 获取https://www.baidu.com/s?wd=周杰伦 的网页源码
print(urllib.parse.quote('周杰伦'))
url='http://www.baidu.com/s?wd='+urllib.parse.quote('周杰伦')
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
}
requestobject=urllib.request.Request(url,headers=headers)

response= urllib.request.urlopen(requestobject)

# 获取响应内容
content=response.read().decode('utf8')

print(content)
